home *** CD-ROM | disk | FTP | other *** search
/ 5 Star Games: DOS Edition 2 / 5 Star Games - DOS Edition (1995)(Ready to Run).iso / dbc / dbcfix.skl < prev    next >
Text File  |  1993-08-25  |  21KB  |  901 lines

  1. #define DBCFIX
  2.  
  3. #ifdef __TURBOC__
  4.     #include <conio.h>
  5. #else
  6.     #include <graph.h>
  7. #endif
  8. #include <io.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include "db_lsc.h"
  13. #include "db_types.h"
  14. #include "db_conio.h"
  15. #include "db_curs.h"
  16. #include "db_date.h"
  17. #include "db_dos.h"
  18. #include "db_file.h"
  19. #include "extfhc.h"
  20. #include "db_funcs.h"
  21. #include "db_heap.h"
  22. #include "db_gvar.h"
  23. #include "db_key.h"
  24. #include "db_math.h"
  25. #include "db_pswd.h"
  26. #include "db_sets.h"
  27. #include "db_str.h"
  28. #include "db_win.h"
  29. #include "db_util.h"
  30. #include "db_tree.h"
  31. #include "db_uwin.h"
  32. ⁿUSESⁿ
  33. ⁿIFDEF MANUALⁿ
  34. #include "db_man.h"
  35. ⁿENDDEFⁿ
  36. ⁿIFDEF MEMOSⁿ
  37. #include "db_mnu.h"
  38. #include "db_memo.h"
  39. ⁿELSEDEFⁿ
  40. #include "db_mnu.h"
  41. ⁿENDDEFⁿ
  42.  
  43. #define startintwin 7
  44. #define numintwin      1
  45. #define _Select     'S'
  46.  
  47. #define maxfilno    ⁿmaxfilnoⁿ
  48. #define maxkeyno    ⁿmaxkeynoⁿ
  49.  
  50. str12 dbnames[maxfilno+1][maxkeyno+1] =
  51.             ⁿdbnamesⁿ;
  52.  
  53. byte keymode[maxfilno+1][maxkeyno+1] =
  54.             ⁿkeymodeⁿ;
  55.  
  56. byte keylen[maxfilno+1][maxkeyno+1] =
  57.             ⁿkeylenⁿ;
  58.  
  59. bool filinuse[maxfilno+1] = ⁿfilinuseⁿ;
  60.  
  61. bool filselected[maxfilno+1] = ⁿfilinuseⁿ;
  62.  
  63. bool menudriven = ⁿmenudrivenⁿ;
  64.  
  65. typedef long recnotyp[maxfilno+1];
  66.  
  67. ⁿIFDEF MEMOSⁿ
  68. bool memos;
  69. ⁿENDDEFⁿ
  70.  
  71. unsigned  _stklen = 0x4000;                      /* Default stack of 16 K */
  72. char      tmpfilnam[13] = "DBFIX._-_";
  73.  
  74. winptr    intwin[numintwin],
  75.           fixwin,
  76.           errwinp,
  77.           msgwinp;
  78. int       savds,
  79.           mtlen,
  80.           tv,
  81.           keyno,
  82.           keynum,
  83.           filno,
  84.           dbsize[maxfilno+1];
  85. bool      _abort,
  86.           fok,
  87.           full_fix;
  88. uchar     ch,
  89.           re_write_data[2];
  90. byte      line;
  91. long      pro_cnt,
  92.           cpy_cnt,
  93.           dup_cnt,
  94.           mem_cnt1,
  95.           mem_cnt2,
  96.           li,
  97.           recs;
  98. string    ws, 
  99.           _tts;
  100. keystr    skey,
  101.           key;
  102. pathstr   prepend;
  103. recnotyp  newno,
  104.           recno;
  105. datafile  tempf,
  106.           *datf[maxfilno+1];
  107. indexfile *idxkey[maxfilno+1][maxkeyno+1];
  108.  
  109. ⁿRECMODⁿ
  110.  
  111. void getarec(int fno);                                /* prototype */
  112.  
  113. /* ⁿFUNCMODⁿ If you include this code it includes your included */
  114. /*            Database functions */
  115.  
  116. void getarec(int fno)
  117. {
  118.     switch (fno) {
  119.         ⁿGetRecⁿ
  120.     }
  121. }
  122.  
  123. void getnewrec(int fno)
  124. {
  125.     switch (fno) {
  126.         ⁿGetNewRecⁿ
  127.     }
  128. }
  129.  
  130. strptr makekey(strptr sout, int fno, int kno)
  131. {
  132.     string ks, ts;
  133.  
  134.     ks[0] = '\0';
  135.  
  136.     ⁿmakekeyⁿ
  137.  
  138.     strcpy(sout,ks);
  139.     return(sout);
  140. }
  141.  
  142. strptr keyexpr(strptr sout, int fno, int kno, string kvar)
  143. {
  144.     string ts, ks;
  145.   byte   tlen;
  146.  
  147.     strcpy(ks,kvar);
  148.   tlen = strlen(ks);
  149.  
  150.     ⁿkeyexprⁿ
  151.  
  152.   ks[tlen] = Nul;
  153.     strcpy(sout,ks);
  154.     return(sout);
  155. }
  156.  
  157. strptr getakey(strptr sout, int fno, int kno)
  158. {
  159.   string tsout;
  160.  
  161.     keyexpr(sout,fno,kno,makekey(tsout,fno,kno));
  162.     return(sout);
  163. }
  164.  
  165.  
  166. void addarec(void)
  167. {
  168.     cpy_cnt++;
  169.     switch (filno) {
  170.         ⁿFIXADDRECⁿ
  171.     }
  172. }
  173.  
  174.  
  175. void openfiles(void)
  176. {
  177.     int     i,j;
  178.     bool    oneopened;
  179.     string  ts;
  180.  
  181.     oneopened = False;
  182.     fok       = True;
  183.  
  184.     ⁿSIZESⁿ
  185.  
  186.     for (i=1; i <= maxfilno; i++)
  187.         if ((fok) && filselected[i]) {
  188.             tmpfilnam[6] = (uchar)(i+64);
  189.                  tmpfilnam[8] = '_';
  190.             datf[i] = db_malloc(sizeof(datafile));
  191.             strconcat(ts,prepend,dbnames[i][0],NULL);
  192.             openfile(datf[i],ts,dbsize[i]);
  193.             fok = ok;
  194.             if (fok) {
  195.                 oneopened = True;
  196.                 for (j=1; j <= maxkeyno; j++)
  197.                     if ((fok) && (keylen[i][j] > 0)) {
  198.                         tmpfilnam[8] = (uchar)(j+64);
  199.                         idxkey[i][j] = db_malloc(sizeof(indexfile));
  200.                         strconcat(ts,prepend,tmpfilnam,NULL);
  201.                         makeindex(idxkey[i][j],ts,keylen[i][j],keymode[i][j]);
  202.                         fok = (bool) (fok && ok);
  203.                     }
  204.             }
  205.             else {
  206.                 fok = True;
  207.                 filselected[i] = False;
  208.             }
  209.         }
  210.     fok = (bool) (fok && oneopened);
  211. }
  212.  
  213.  
  214. void display_files(void)
  215. {
  216.     int i,j;
  217.     string ts;
  218.  
  219.     i = j = 1;
  220.     do {
  221.         if (filinuse[i]) {
  222.             pad(ts,dbnames[i][0],12,1);
  223.             writewxy(ts,112,(byte)(23+(((j-1)%4)*13)),(byte)(12+(((j-1)/4)*2)),fixwin);
  224.             j++;
  225.         }
  226.         i++;
  227.     } while (i <= maxfilno);
  228. }
  229.  
  230.  
  231. void high(int j)
  232. {
  233.     uchar cs[2];
  234.  
  235.     writewxy(chstr(cs,31),159,(byte)(28+(((j-1)%4)*13)),(byte)(11+(((j-1)/4)*2)),fixwin);
  236.     writewxy(chstr(cs,16),159,(byte)(22+(((j-1)%4)*13)),(byte)(12+(((j-1)/4)*2)),fixwin);
  237.     writewxy(chstr(cs,17),159,(byte)(35+(((j-1)%4)*13)),(byte)(12+(((j-1)/4)*2)),fixwin);
  238.     writewxy(chstr(cs,30),159,(byte)(28+(((j-1)%4)*13)),(byte)(13+(((j-1)/4)*2)),fixwin);
  239. }
  240.  
  241.  
  242. void low(int j)
  243. {
  244.     uchar cs[2];
  245.  
  246.     writewxy(chstr(cs,'─'),31,(byte)(28+(((j-1)%4)*13)),(byte)(11+(((j-1)/4)*2)),fixwin);
  247.     writewxy(chstr(cs,'│'),31,(byte)(22+(((j-1)%4)*13)),(byte)(12+(((j-1)/4)*2)),fixwin);
  248.     writewxy(chstr(cs,'│'),31,(byte)(35+(((j-1)%4)*13)),(byte)(12+(((j-1)/4)*2)),fixwin);
  249.     writewxy(chstr(cs,'─'),31,(byte)(28+(((j-1)%4)*13)),(byte)(13+(((j-1)/4)*2)),fixwin);
  250. }
  251.  
  252.  
  253. void select_files(void)
  254. {
  255.     int    i, j, count, save_i, save_j;
  256.     string ts;
  257.     uchar  pic[2];
  258.  
  259.     i = j = 1;
  260.     do {
  261.         high(j);
  262.         count  = 4;
  263.       save_i = i;
  264.       save_j = j;
  265.         do {
  266.             ch = upperch(getkey());
  267.         } while ((ch != Esc) && (ch != XeptKey) && (ch != _NO) &&
  268.                                         (ch != _Select) && (ch != _YES) &&
  269.                             !((ch == RArr) && (i < 16) && (i < maxfilno)) &&
  270.                             !((ch == LArr) && (i > 1)) &&
  271.                             !((ch == UArr) && (i > 4)) &&
  272.                             !((ch == DArr) && (i < 13) && (i < (maxfilno-3))));
  273.  
  274.         switch (ch) {
  275.             case Esc     :
  276.             case XeptKey : break;
  277.             case _NO  :
  278.             case _YES :
  279.                 chstr(re_write_data,ch);
  280.                 dsp_fld(68,21,re_write_data,_Ch,chstr(pic,Pic_U),0,0,0,fixwin);
  281.                break;
  282.             case RArr :
  283.                 low(j);
  284.                 do
  285.                     if (filinuse[++i]) j++;
  286.                 while (!filinuse[i] && (i < maxfilno));
  287.                break;
  288.             case LArr :
  289.                 low(j);
  290.                 do
  291.                     if (filinuse[--i]) j--;
  292.                 while (!filinuse[i] && (i > 1));
  293.                break;
  294.             case DArr :
  295.                 low(j);
  296.                 count = 0;
  297.                 do
  298.                     if (filinuse[++i]) {
  299.                         j++;
  300.                         count++;
  301.                     }
  302.                 while ((count != 4) && (i < maxfilno));
  303.                break;
  304.             case UArr :
  305.                 low(j);
  306.                 count = 0;
  307.                 do
  308.                     if (filinuse[--i]) {
  309.                         j--;
  310.                         count++;
  311.                     }
  312.                 while ((count != 4) && (i > 1));
  313.                break;
  314.             case 'S'  :
  315.                 filselected[i] = (bool) (!filselected[i]);
  316.                 if (filselected[i])
  317.                     writewxy(pad(ts,dbnames[i][0],12,1),
  318.                                 112,(byte)(23+(((j-1)%4)*13)),(byte)(12+(((j-1)/4)*2)),fixwin);
  319.                 else
  320.                     writewxy(pad(ts,dbnames[i][0],12,1),
  321.                                 31,(byte)(23+(((j-1)%4)*13)),(byte)(12+(((j-1)/4)*2)),fixwin);
  322.                break;
  323.         }
  324.         if ((count != 4) || (i > maxfilno) || (i < 1) || !filinuse[i]) {
  325.             i = save_i;
  326.             j = save_j;
  327.         }
  328.     } while ((ch != Esc) && (ch != XeptKey));
  329.     exitcode = ch;
  330. }
  331.  
  332.  
  333. void pick_files(void)
  334. {
  335.     uchar pic[2];
  336.  
  337.     hidewin(T_ON, fixwin);
  338.     chstr(re_write_data, _YES);
  339.     dsp_fld(68, 21, re_write_data, _Ch, chstr(pic,Pic_U), 0, 0, 0, fixwin);
  340.     display_files();
  341.     select_files();
  342.     hidewin(T_OFF,fixwin);
  343. }
  344.  
  345.  
  346. ⁿIFDEF MEMOSⁿ
  347. void deletememos(void *fb, void *buf, int fno)
  348. {
  349.     word   w;
  350.     long   mrec,
  351.           trec;
  352.     genbuf sbuf;
  353.     fldblk *fblk;
  354.     fldtyp *ftp;
  355.     byte   *buffer;
  356.  
  357.     buffer = buf;
  358.     fblk   = fb;
  359.     getrec(&tempf, recno[fno], buf);
  360.     memmove(sbuf, buf, fblk->dsz);
  361.     w = 0;
  362.     do {
  363.         ftp = &(*fblk->farr)[w];
  364.         if (ftp->typ == _Memo) {
  365.             memmove(&mrec, ftp->faddr, 4);
  366.             while (mrec != 0) {
  367.                 mem_cnt2--;
  368.                 getrec(&tempf, mrec, buf);
  369.                 memmove(&trec, &buffer[(fblk->dsz - 3) - 1], 4);
  370.                 deleterec(&tempf, mrec);
  371.                 mrec = trec;
  372.             }
  373.             memmove(buf,sbuf,fblk->dsz);
  374.         }
  375.         w++;
  376.     } while (w < fblk->numf);
  377. }
  378.  
  379.  
  380. void removememo(int fno, long drno)
  381. {
  382.     recno[fno] = drno;
  383.     switch (fno) {
  384.         ⁿDELMEMOSⁿ
  385.     }
  386. }
  387. ⁿENDDEFⁿ
  388.  
  389.  
  390. void display_fields(int fn, fldblk *fb, int f, string k, long *r, ptr buf,winptr w)
  391. {
  392.     int next;
  393.     string ts;
  394.     uchar header[76],data1[76],data2[76];
  395.  
  396.    strconcat(header, LSC_KeyValue, '"', k, '"', NULL);
  397.     data1[0] = data2[0] = '\0';
  398.     next = f; 
  399.    getrec(&tempf, newno[fn], buf);
  400.  
  401.     ts[0] = '\0';
  402.     do {
  403.         if ((*fb->farr)[next-1].typ != _Memo)           /* check for -> not . */
  404.             strconcat(ts, ts, " │ ", (*fb->farr)[next-1].faddr, NULL);
  405.             next++;
  406.     } while ((strlen(ts) < 75) && (next <= fb->numf));
  407.  
  408.     strcopy(data1,ts,0,75);
  409.     next = f;
  410.     getrec(&tempf, *r, buf);
  411.     ts[0] = '\0';
  412.     do {
  413.         if ((*fb->farr)[next-1].typ != _Memo)
  414.             strconcat(ts,ts," │ ",(*fb->farr)[next-1].faddr,NULL);
  415.         next++;
  416.     } while ((strlen(ts) < 75) && (next <= fb->numf));
  417.  
  418.     strcopy(data2,ts,0,75);
  419.     pad(data1,data1,75,Right);
  420.     pad(data2,data2,75,Right);
  421.     writewxy(header,0,4,1,w);
  422.     writewxy(data1,78,4,2,w);
  423.     writewxy(data2,78,4,3,w);
  424. }
  425.  
  426. void pickone(int fn, fldblk *fb, int *it, string k, long *r, ptr buf, winptr w)
  427. {
  428.     uchar ch;
  429.     int fld;
  430.     string ts;
  431.  
  432.     writewxy(pad(ts,LSC_DupMenu,78,Right),0,1,4,w);
  433.     fld = 1;
  434.     do {
  435.         display_fields(fn, fb, fld, k, r, buf, w);
  436.         switch (*it) {
  437.             case 1 :
  438.                 writewxy("-->",0,1,2,w); 
  439.             writewxy("   ",0,1,3,w);
  440.                break;
  441.             case 2 :
  442.                 writewxy("   ",0,1,2,w); 
  443.             writewxy("-->",0,1,3,w);
  444.                break;
  445.         }
  446.  
  447.         do
  448.             ch = getkey();
  449.         while ((ch != Esc) && (ch != XeptKey) && (ch != Enter ) &&
  450.                         (ch != UArr) && (ch != DArr) &&
  451.                         !((ch == LArr) && (fld > 1)) &&
  452.                         !((ch == RArr) && (fld < fb->numf)));
  453.  
  454.         switch(ch) {
  455.             case UArr    :
  456.             case DArr    : *it = (*it % 2)+1; break;
  457.             case RArr    : fld++; break;
  458.             case LArr    : fld--; break;
  459.             case Esc     : *it = 0; break;
  460.             case XeptKey : *it = 3; break;
  461.         }
  462.     } while ((ch != Esc) && (ch != XeptKey) && (ch != Enter));
  463. }
  464.  
  465. void makechoice(int fno, int kno, string k)
  466. {
  467.     int    i,
  468.           choice;
  469.     long   rec_no,
  470.           delrecno;
  471.     keystr tkey;
  472.     fldblk *fblk;
  473.     ptr    buf;
  474.     string ts;
  475.     winptr choosewinp;
  476.  
  477.     switch (fno) {
  478.         ⁿBUFFERⁿ
  479.     }
  480.  
  481.     choice = 1;
  482.     findkey(idxkey[fno][kno], &rec_no, k);
  483.     if ((ok) && openwin(0,2,20,78,4,31,31,8,"─┐│┘─└│┌",TopCnt,"")) {
  484.         choosewinp       = curwin;
  485.       choosewinp->disp = True;
  486.       dispwindow(choosewinp);
  487.         pickone(fno,fblk,&choice,k,&rec_no,buf,choosewinp);
  488.  
  489.         switch (choice) {
  490.             case 0 :
  491.                 cpy_cnt--; 
  492.             dup_cnt++;
  493.                 delrecno = rec_no;
  494. ⁿIFDEF MEMOSⁿ
  495.                 if (memos) removememo(fno, delrecno);
  496. ⁿENDDEFⁿ
  497.                 deleterec(&tempf, delrecno);
  498.                 for (i=1; i <= maxkeyno; i++)
  499.                     if (keylen[fno][i] > 0) {
  500.                         delrecno = rec_no;
  501.                         getakey(tkey, fno,i);
  502.                         deletekey(idxkey[fno][i], &delrecno, tkey);
  503.                     }
  504.                 delrecno = newno[fno];
  505.                 cpy_cnt--; 
  506.             dup_cnt++;
  507. ⁿIFDEF MEMOSⁿ
  508.                 if (memos) removememo(fno, delrecno);
  509. ⁿENDDEFⁿ
  510.                 deleterec(&tempf, delrecno);
  511.                 for (i=1; i < maxkeyno; i++)
  512.                     if (keylen[fno][i] > 0) {
  513.                         delrecno = newno[fno];
  514.                         getakey(tkey, fno, i);
  515.                         deletekey(idxkey[fno][i], &delrecno, tkey);
  516.                     }
  517.                 _abort = True;
  518.                break;
  519.             case 1 :
  520.                 cpy_cnt--; 
  521.             dup_cnt++;
  522.                 delrecno = rec_no;
  523. ⁿIFDEF MEMOSⁿ
  524.                 if (memos) removememo(fno, delrecno);
  525. ⁿENDDEFⁿ
  526.                 deleterec(&tempf, delrecno);
  527.                 for (i=1; i <= maxkeyno; i++)
  528.                     if (keylen[fno][i] > 0) {
  529.                         delrecno = rec_no;
  530.                         getakey(tkey, fno, i);
  531.                         deletekey(idxkey[fno][i], &delrecno, tkey);
  532.                     }
  533.                 getakey(tkey, fno, kno);
  534.                 addkey(idxkey[fno][kno], &newno[fno], tkey);
  535.                 if (!ok) {
  536.                     audible(Error);
  537.                     tv = max(max(strlen(LSC_DupFound)+3,strlen(LSC_KeyValue)+36),strlen(LSC_PressAnyKey));
  538.                     if (openwin(0,(80-tv)/2,12,(byte)tv,3,78,78,8,"─┐│┘─└│┌",TopCnt,"")){
  539.                         errwinp = curwin;
  540.                         errwinp->disp = True;
  541.                         dispwindow(errwinp);
  542.                         strconcat(ts,LSC_DupFound," ",istr(ts,(long)kno,2),NULL);
  543.                         writewxy(ts,78,1,1,errwinp);
  544.                         strconcat(ts,LSC_KeyValue," ",strcopy(ts,tkey,1,35),NULL);
  545.                         writewxy(ts,78,1,2,errwinp);
  546.                         writewxy(LSC_PressAnyKey,78,1,3,errwinp);
  547.                         ch = getkey();
  548.                         closewin(&errwinp);
  549.                     }
  550.                 }
  551.                break;
  552.             case 2 :
  553.                 cpy_cnt--; 
  554.             dup_cnt++;
  555.                 delrecno = newno[fno];
  556. ⁿIFDEF MEMOSⁿ
  557.                 if (memos) removememo(fno, delrecno);
  558. ⁿENDDEFⁿ
  559.                 deleterec(&tempf, delrecno);
  560.                 for (i=1; i < maxkeyno; i++)
  561.                     if (keylen[fno][i] > 0) {
  562.                         delrecno = newno[fno];
  563.                         getakey(tkey, fno, i);
  564.                         deletekey(idxkey[fno][i], &delrecno, tkey);
  565.                     }
  566.                 _abort = True;
  567.                break;
  568.             case 3 :
  569.                break;
  570.         }
  571.         closewin(&choosewinp);
  572.     }
  573. }
  574.  
  575.  
  576. ⁿIFDEF MEMOSⁿ
  577. bool anymemos(ptr fb)
  578. {
  579.     word w;
  580.     fldblk *fblk;
  581.  
  582.     fblk = fb;                                         /* checkout -> for . */
  583.     w = 1;
  584.     while (((*fblk->farr)[w-1].typ != _Memo) && (w < fblk->numf)) w++;
  585.     return((bool) ((*fblk->farr)[w-1].typ == _Memo));
  586. }
  587.  
  588.  
  589. void addmemos(ptr fb, ptr buf)
  590. {
  591.     word   w;
  592.     fldblk *fblk;
  593.     long   first,
  594.           savm,
  595.           tr1,
  596.           tr2;
  597.     genbuf sbuf;
  598.     fldtyp *ftp;
  599.     byte   *buffer;
  600.  
  601.     buffer = buf;
  602.     fblk = fb;
  603.     w = 1;
  604.     while (w <= fblk->numf) {
  605.         while ((w <= fblk->numf) && ((*fblk->farr)[w-1].typ != _Memo)) w++;
  606.         ftp = &(*fblk->farr)[w-1];
  607.         if (w <= fblk->numf) {
  608.             first = 0;
  609.             memmove(&savm, ftp->faddr, 4);
  610.             memmove(sbuf, buf, fblk->dsz);
  611.             if (savm) addrec(&tempf, &tr1, buf);
  612.  
  613.             while (savm) {
  614.                 mem_cnt2++;
  615.                 if (!first) first = tr1;
  616.                 getrec(datf[filno], savm, buf);
  617.                 memmove(&savm, &buffer[(fblk->dsz-3)-1], 4);
  618.                 if (savm) addrec(&tempf, &tr2, buf);
  619.                 else      tr2 = 0;
  620.                 memmove(&buffer[(fblk->dsz-3)-1],&tr2,4);
  621.                 putrec(&tempf,tr1,buf);
  622.                 tr1 = tr2;
  623.             }
  624.             memmove(buf,sbuf,fblk->dsz);
  625.             memmove(ftp->faddr,&first,4);
  626.         }
  627.         w++;
  628.     }
  629. }
  630. ⁿENDDEFⁿ
  631.  
  632.  
  633. strptr amount_done(strptr sout)
  634. {
  635.     string ts;
  636.    float  howManyBlocks, howManyProcessed, howManyRecords;
  637.  
  638.    howManyProcessed = li;
  639.    howManyRecords   = recs;
  640.     howManyBlocks = (float)fround((double)(howManyProcessed/howManyRecords)*55);
  641.     fillstr(ts,(int)howManyBlocks,'█');
  642.     strcpy(sout,ts);
  643.     return(sout);
  644. }
  645.  
  646. void deleteTempIndexes(void)
  647. {
  648.      string mts;
  649.  
  650.      for (filno=filno; filno <= maxfilno; filno++) if (filselected[filno]) {
  651.             tmpfilnam[6] = (uchar)(filno+64);
  652.             tmpfilnam[8] = '_';
  653.             for (keyno=1; keyno<=maxkeyno; keyno++)
  654.                  if (keylen[filno][keyno] > 0) {
  655.                         tmpfilnam[8] = (uchar)(keyno+64);
  656.                         closeindex(idxkey[filno][keyno]);
  657.                         db_free(idxkey[filno][keyno]);
  658.                         unlink(strconcat(mts,prepend,tmpfilnam,NULL));
  659.                  }
  660.      }
  661. }
  662.  
  663. void main(void)
  664. {
  665.     uchar *mtp;
  666.     string mts,
  667.                     mts1;
  668.     strptr tp;
  669.  
  670.     extfhc_init();
  671.     db_curs_init();
  672.     db_date_init();
  673.     db_funcs_init();
  674.     db_heap_init();
  675.     db_gvar_init();
  676.     db_key_init();
  677.     db_pswd_init();
  678.     db_win_init();
  679.     db_util_init();
  680.     db_tree_init();
  681. ⁿIFDEF MEMOSⁿ
  682.     db_mnu_init();
  683.     db_memo_init();
  684. ⁿELSEDEFⁿ
  685.     db_mnu_init();
  686. ⁿENDDEFⁿ
  687.  
  688.     clrscr();
  689.    line = 1;
  690.    ignoresizediff = True;
  691. /*
  692. ⁿIFDEF MUSERⁿ
  693.    filemode = (int)0x12;
  694. ⁿENDDEFⁿ
  695. */
  696. /*  CHECK WITH ALEX !!!!!!!!!!!!
  697.  
  698.    readinternal("DB_UTIL.IWF",startintwin,numintwin,intwin);
  699.     readlang("DBLANG.LAN","DBPFIXSK",&langp);
  700.  
  701. */
  702.  
  703.     initedit();
  704.     initindex();
  705.     if (menudriven && !dbcaller) {
  706.         audible(Error);
  707.         dspmsge(LSC_BaseError,LSC_MenuDriven,4.0);
  708.     }
  709.     else if (!validpath()) {
  710.         audible(Error);
  711.         dspmsge(LSC_BaseError,LSC_AbortBadPath,4.0);
  712.     }
  713.     else {
  714.       fixwin = FixFilesWin();
  715.         strip(prepend,datapath);
  716.         tp = strchr(prepend,'\0');
  717.         if (tp != NULL) if (*(tp-1) != '\\') {
  718.             *tp++ = '\\'; *tp = '\0';
  719.         }
  720.  
  721.         pick_files();
  722.         if (exitcode == QitKey) goto fix_exit;
  723.  
  724.         full_fix = (bool) (re_write_data[0] == _YES);
  725.         mtlen = strlen(LSC_Initializing);
  726.         if (openwin(0,(80-mtlen)/2,12,(byte)mtlen,1,31,31,8,"─┐│┘─└│┌",TopCnt,"")){
  727.             msgwinp = curwin; 
  728.          msgwinp->disp = True; 
  729.          dispwindow(msgwinp);
  730.             writewxy(LSC_Initializing,0,1,1,msgwinp);
  731.             hidewin(T_ON,msgwinp);
  732.             openfiles();
  733.             closewin(&msgwinp);
  734.         }
  735.  
  736.         if (fok) {
  737.             savds = deltas;
  738.          deltas = 0;
  739.             strconcat(fixwin->title,LSC_FixModule,"ⁿMODNAMEⁿ",NULL);
  740.                  clrwin(fixwin);
  741.             hidewin(T_ON,fixwin);
  742.             writewxy(LSC_ProcessedHdr,0,1,1,fixwin);
  743.  
  744.             for (filno=1; filno <= maxfilno; filno++) if (filselected[filno]) {
  745. ⁿIFDEF MEMOSⁿ
  746.                 switch (filno) {
  747.                     ⁿANYMEMOSⁿ
  748.                 }
  749. ⁿENDDEFⁿ
  750.  
  751.                 writewxy(centre(mts,LSC_Any2Abort,78),0,1,23,fixwin);
  752.                 line++;
  753.                 writewxy(dbnames[filno][0],0,1,line,fixwin);
  754.                 if (full_fix) {
  755.                     tmpfilnam[6] = (uchar)(filno+64);
  756.                              tmpfilnam[8] = '_';
  757.                     makefile(&tempf, strconcat(mts,prepend,tmpfilnam,NULL), dbsize[filno]);
  758.                     if (!ok) {
  759.                         audible(Error);
  760.                         dspmsge(LSC_BaseError,strconcat(mts,LSC_NoCreateTemp," ",tmpfilnam,NULL),4.0);
  761.                         goto fix_exit;
  762.                     }
  763.                 }
  764.                 recno[filno] = newno[filno] = 0;
  765.                 recs = filelen(datf[filno])-1;
  766.             pro_cnt = recs;
  767.                 cpy_cnt = dup_cnt = mem_cnt1 = mem_cnt2 = 0;
  768.                 for (keyno=1; keyno <= maxkeyno; keyno++) if (keylen[filno][keyno] != 0) {
  769.                     if ((keyno > 1) && full_fix) recs = filelen(&tempf) - 1;
  770.                     writewxy("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░",0,24,line,fixwin);
  771.                     for (li=1; li <= recs; li++) {
  772.                         writewxy(amount_done(mts),0,24,line,fixwin);
  773.                         _abort = False;
  774.                         recno[filno] = newno[filno] = li;
  775.                         if ((keyno == 1) || !full_fix) getarec(filno); 
  776.                   else                           getnewrec(filno);
  777.                         switch (filno) {
  778.                             ⁿSETOKⁿ
  779.                         }
  780.                         if (ok) {
  781.                             if ((keyno == 1) && full_fix) {
  782. ⁿIFDEF MEMOSⁿ
  783.                                 if (memos)
  784.                                     switch (filno) {
  785.                                         ⁿADDMEMOSⁿ
  786.                                     }
  787. ⁿENDDEFⁿ
  788.                                 addarec();
  789.                             }
  790.                             else {
  791.                                 switch (filno) {
  792.                                     ⁿCHKRECⁿ
  793.                                 }
  794.                             }
  795.                             if (ok) {
  796.                                 getakey(key,filno,keyno);
  797.                                 if (full_fix)
  798.                                     addkey(idxkey[filno][keyno],&newno[filno],key);
  799.                                 else
  800.                                     addkey(idxkey[filno][keyno],&recno[filno],key);
  801.                                 if (!ok) {
  802.                                     audible(Error);
  803.                                     tv = max(strlen(LSC_DupFound)+3,strlen(LSC_KeyValue)+36);
  804.                                     if (openwin(0,(80-tv)/2,8,(byte)tv,3,78,78,8,"─┐│┘─└│┌",TopCnt,"")) {
  805.                                         errwinp = curwin; 
  806.                               errwinp->disp = True; 
  807.                               dispwindow(errwinp);
  808.                                         strconcat(mts,LSC_DupFound," ",istr(mts,(long)keyno,2),NULL);
  809.                                         writewxy(mts,78,1,1,errwinp);
  810.                                         strconcat(mts,LSC_KeyValue," ",strcopy(mts,key,0,35),NULL);
  811.                                         writewxy(mts,78,1,3,errwinp);
  812.                                                             gotoxy(1,1);
  813.                                         if (full_fix) makechoice(filno,keyno,key);
  814.                                         else          dspmsge("",LSC_PressAnyKey,4.0);
  815.                                         closewin(&errwinp);
  816.                                     }
  817.                                 }
  818.                                 if (kpressed()) {
  819.                                     audible(Warning);
  820.                                     ch = getkey();
  821.                                     tv = max(strlen(LSC_XeptOrEsc),strlen(LSC_PartialFixWarn));
  822.                                     if (openwin(0,(80-tv)/2,5,(byte)tv,3,78,78,8,"─┐│┘─└│┌",TopCnt,"")) {
  823.                                         errwinp = curwin; 
  824.                               errwinp->disp = True; 
  825.                               dispwindow(errwinp);
  826.                                         writewxy(centre(mts,LSC_XeptOrEsc,tv),78,1,1,errwinp);
  827.                                         writewxy(centre(mts,LSC_PartialFixWarn,tv),78,1,3,errwinp);
  828.                                         do
  829.                                             ch = getkey();
  830.                                         while ((ch != Esc) && (ch != XeptKey));
  831.                                         closewin(&errwinp);
  832.                                     }
  833.                                     if (ch == Esc) {
  834.                                         closefile(datf[filno]);
  835.                                         db_free(datf[filno]);
  836.                                         if (full_fix) {
  837.                                             closefile(&tempf);
  838.                                             unlink(strconcat(mts,prepend,tmpfilnam,NULL));
  839.                                         }
  840.                                         deleteTempIndexes();
  841.                                         dspmsge("",LSC_ClosingFile,4.0);
  842.                                         goto fix_exit;
  843.                                     }
  844.                                 }
  845.                             }
  846.                             writewxy(istr(mts,li,6),0,14,line,fixwin);
  847.                         }
  848.                     }
  849.                     writewxy(istr(mts,pro_cnt-mem_cnt1,6),0,14,line,fixwin);
  850.                 }
  851.                 closefile(datf[filno]);
  852.                 db_free(datf[filno]);
  853.                 tmpfilnam[6] = (uchar)(filno+64);
  854.             tmpfilnam[8] = '_';
  855.                 if (full_fix) {
  856.                     strconcat(ws,LSC_CopiedEquals," ",strip(mts,istr(mts,cpy_cnt,6)),",",NULL);
  857.                     pad(ws,ws,15,Right);
  858.                     strconcat(mts,LSC_PurgedEquals," ",strip(mts,istr(mts,
  859.                                         pro_cnt-mem_cnt1-cpy_cnt-dup_cnt,6)),",",NULL);
  860.                     strconcat(ws,ws,pad(mts,mts,14,Right),NULL);
  861.                     strconcat(mts,LSC_DeletedEquals," ",strip(mts,istr(mts,dup_cnt,6)),
  862.                                         " ",LSC_DupsEquals,NULL);
  863.                     strconcat(ws,ws,pad(mts,mts,26,Right),NULL);
  864.                     writewxy(ws,0,24,line,fixwin);
  865.                     closefile(&tempf);
  866.                     unlink(strconcat(mts,prepend,dbnames[filno][0],NULL));
  867.                     rename(strconcat(mts,prepend,tmpfilnam,NULL),
  868.                                  strconcat(mts1,prepend,dbnames[filno][0],NULL));
  869.                 }
  870.                 for (keyno=1; keyno<=maxkeyno; keyno++)
  871.                     if (keylen[filno][keyno] > 0) {
  872.                         tmpfilnam[8] = (uchar)(keyno+64);
  873.                         closeindex(idxkey[filno][keyno]);
  874.                         db_free(idxkey[filno][keyno]);
  875.                         unlink(strconcat(mts,prepend,dbnames[filno][keyno],NULL));
  876.                         rename(strconcat(mts,prepend,tmpfilnam,NULL),
  877.                                      strconcat(mts1,prepend,dbnames[filno][keyno],NULL));
  878.                     }
  879.             }
  880.             strconcat(mts,"\xFF\x01",chstr(mts,fixwin->mwid),"\x20",NULL);
  881.             writewxy(mts,0,1,23,fixwin);
  882.             audible(Warning);
  883.             message(NULL,LSC_Finished);
  884.             deltas = savds;
  885.             ch = getkey();
  886.             message(NULL,"");
  887.  
  888. fix_exit:;
  889.             hidewin(T_OFF,fixwin);
  890.         }
  891.         else {
  892.             audible(Error);
  893.             dspmsge(LSC_ErrNeededFiles,LSC_ErrMissingFile,4.0);
  894. ⁿIFDEF MUSERⁿ
  895.             dspmsge("",LSC_DeniedFiles,4.0);
  896. ⁿENDDEFⁿ
  897.         }
  898.     }
  899.     clrscr();
  900. }
  901.